/**
 * Created by chengming on 18/5/27.
 * version 1.0
 */
const BaseJsonAdapter = require('../base/BaseJsonAdapter');
const ArticleHrefAdapter = require('../ArticleHrefAdapter');
const iconv = require("iconv-lite");
const vm = require('vm');
const request = require('request-promise');
const logger = require('../../conf/logger');
const querystring = require("querystring")
const cheerio = require('cheerio');
const urlTool = require('url');
const crypto = require('crypto')

/**
 * 北京互金网
 * @type {module.Bjp2p}
 */
module.exports = class CoinessEn extends BaseJsonAdapter {

    async doRequest() {
        let now = new Date().getTime();
        let md5 = crypto.createHash('md5')
        let md5Str = '?size=10&signature=' + md5.update(now+'b3290f72866a06136674b380a92446fesize=10').digest('hex') +'&ts=' + now;
        let url = this.requestUrl + md5Str;
        var options = {
            // uri:'http://www.bjp2p.com.cn/supervise/queryNews4List',
            uri: url,
            method: "GET",
            encoding: null
        }
        let body = await request(options)
        return body;
    }


    async reqJson(){
        const body = await this.doRequest();
        let decodeBody = iconv.decode(body, this.encoding).toString();
        // decodeBody = urlencode.decode(decodeBody,this.encoding);
        // decodeBody = decodeBody.replace(/\\/g,'');
        // decodeBody = decodeBody.substr(1,decodeBody.length-2);
        let data = JSON.parse(decodeBody);
        console.log("-----decodeBody: " + decodeBody)
        return data;
    }


}
